package com.my.study.view;

import com.my.study.service.UserClientService;
import com.my.study.utils.Utility;

/**
 * @author Carlos
 * @version 1.0
 * @Description QQ菜单界面
 * @date 2021/7/18 9:52
 **/
public class QQView {

    public static void main(String[] args) {
        new QQView().mainMenu();
        System.out.println("退出系统............");
    }

    private boolean loop = true;

    /**
     * 用户键盘输入
     */
    private String key = "";

    private UserClientService userClientService = new UserClientService();

    private void mainMenu() {

        while (loop) {
            System.out.println("=============欢迎登录网络通信系统=============");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入你的选择：");
            key = Utility.readString(1);

            switch (key) {
                case "1":
                    System.out.print("请输入用户号：");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密  码：");
                    String pwd = Utility.readString(50);

                    boolean checkUser = userClientService.checkUser(userId, pwd);

                    if (checkUser) {
                        System.out.println("===============欢迎 (用户" + userId + ")===============");
                        // 进入二级菜单
                        while (loop) {
                            System.out.println("=============网络通信系统二级菜单 (用户" + userId + ")=============");
                            System.out.println("\t\t 1 显示在线用户列表");
                            System.out.println("\t\t 2 群发消息");
                            System.out.println("\t\t 3 私聊消息");
                            System.out.println("\t\t 4 发送文件");
                            System.out.println("\t\t 9 退出系统");

                            System.out.print("请输入你的选择：");
                            key = Utility.readString(1);
                            switch (key) {
                                case "1":
                                    System.out.println("显示在线用户列表");
                                    break;
                                case "2":
                                    System.out.println("群发消息");
                                    break;
                                case "3":
                                    System.out.println("私聊消息");
                                    break;
                                case "4":
                                    System.out.println("发送文件");
                                    break;
                                case "9":
                                    loop = false;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    // 登录服务器失败
                    else {
                        System.out.println("登录服务器失败");
                    }
                    break;
                case "9":
                    loop = false;
                    break;
                default:
                    break;
            }

        }

    }


}
